package org.usmile.algorithms.huawei.acm;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

// https://fcqian.blog.csdn.net/article/details/128271953
public class _静态扫描 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int m = sc.nextInt();
        sc.nextLine();
        Integer[] fileIds = Arrays.stream(sc.nextLine().split(" ")).map(Integer::parseInt).toArray(Integer[]::new);
        Integer[] weights = Arrays.stream(sc.nextLine().split(" ")).map(Integer::parseInt).toArray(Integer[]::new);
        Map<Integer, int[]> fileMap = new HashMap<>();
        for (int i = 0; i < fileIds.length; i++) {
            int fileId = fileIds[i];
            int fileWeight = weights[i];
            if (!fileMap.containsKey(fileId)) {
                fileMap.put(fileId, new int[]{fileWeight, 0});
            }
            fileMap.get(fileId)[1]++;
        }

        int min = 0;
        for (int[] value : fileMap.values()) {
            int weight = value[0];
            int count = value[1];
            int notCache = weight * count;
            int cache = weight + (count - 1) * m;
            min += Math.min(notCache, cache);
        }

        System.out.println(min);
    }
}
